/*     */ package com.zimbra.cs.account.krb5;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.EmailUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Krb5Principal
/*     */ {
/*     */   public static Account getAccountFromKrb5Principal(String principal, boolean loadFromMaster)
/*     */     throws ServiceException
/*     */   {
/*  33 */     Provisioning prov = Provisioning.getInstance();
/*  34 */     Account acct = null;
/*     */     
/*     */ 
/*     */ 
/*     */     try
/*     */     {
/*  40 */       acct = prov.get(Key.AccountBy.foreignPrincipal, "kerberos5:" + principal, loadFromMaster);
/*     */     } catch (ServiceException e) {
/*  42 */       throw e;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  52 */     if (acct == null) {
/*  53 */       int idx = principal.indexOf('@');
/*  54 */       if (idx != -1) {
/*  55 */         String realm = principal.substring(idx + 1);
/*     */         
/*  57 */         Domain domain = prov.get(Key.DomainBy.krb5Realm, realm);
/*  58 */         if (domain != null) {
/*  59 */           String localPart = principal.substring(0, idx);
/*  60 */           String acctName = localPart + "@" + domain.getName();
/*  61 */           acct = prov.get(Key.AccountBy.name, acctName, loadFromMaster);
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*  67 */     return acct;
/*     */   }
/*     */   
/*     */   public static Domain getDomainByKrb5Principal(String principal) throws ServiceException {
/*  71 */     Provisioning prov = Provisioning.getInstance();
/*  72 */     int idx = principal.indexOf('@');
/*  73 */     if (idx != -1) {
/*  74 */       String realm = principal.substring(idx + 1);
/*  75 */       return prov.get(Key.DomainBy.krb5Realm, realm);
/*     */     }
/*     */     
/*  78 */     return null;
/*     */   }
/*     */   
/*     */   public static String getKrb5Principal(Account acct) throws ServiceException {
/*  82 */     Domain domain = Provisioning.getInstance().getDomain(acct);
/*  83 */     return getKrb5Principal(domain, acct);
/*     */   }
/*     */   
/*     */   public static String getKrb5Principal(Domain domain, Account acct) {
/*  87 */     String principal = null;
/*  88 */     String[] fps = acct.getMultiAttr("zimbraForeignPrincipal");
/*  89 */     if ((fps != null) && (fps.length > 0)) {
/*  90 */       for (String fp : fps) {
/*  91 */         if (fp.startsWith("kerberos5:")) {
/*  92 */           int idx = fp.indexOf(':');
/*  93 */           if (idx != -1) {
/*  94 */             principal = fp.substring(idx + 1);
/*  95 */             break;
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 100 */     if (principal == null) {
/* 101 */       String realm = domain.getAttr("zimbraAuthKerberos5Realm");
/* 102 */       if (realm != null) {
/* 103 */         String[] parts = EmailUtil.getLocalPartAndDomain(acct.getName());
/* 104 */         if (parts != null) {
/* 105 */           principal = parts[0] + "@" + realm;
/*     */         } else {
/* 107 */           principal = acct.getName() + "@" + realm;
/*     */         }
/*     */       }
/*     */     }
/* 111 */     return principal;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/krb5/Krb5Principal.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */